<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('根证书管理')" />
	<th:block th:include="include :: bootstrap-select-css" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="form">
					<div class="select-list">
						<ul>
						
							<li>
								证书状态：<select name="status">
									<option value="">所有</option>
									<option value="NORMAL">正常</option>
									<option value="REVOKE">吊销</option>
									<option value="EXPIRE">过期</option>
								</select>
							</li>

							<li>
								 <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
			<div class="btn-group-sm" id="toolbar" role="group">
			 <a class="btn btn-success" onclick="issueRootCa()">
                    <i class="fa fa-plus"></i> 颁发根证书
                </a>
	        </div>
	        
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-tree-table"></table>
			</div>
		</div>
	</div>
	
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: bootstrap-select-js" />
	<script th:inline="javascript">
	
		
		var prefix = ctx + "ca";

		$(function() {
		    var options = {
		    	code: "id",
				parentCode: "parentId",
				uniqueId: "id",
				expandAll: false,
				expandFirst: false,
		        url: prefix + "/rootCaList",
		        modalName: "根证书管理",
		        escape: true,
		        showPageGo: true,
		        rememberSelected: true,
		        columns: [{
                    field: 'selectItem', 
                    radio: true
                 },
		        {
		            field: 'certName',
		            title: 'CA名称',
		            width: '15',
		            widthUnit: '%'
		        },
		        {
		            field: 'serialNumber',
		            title: '序列号',
		            width: '15',
		            widthUnit: '%'
                }/* ,
		        {
		            field: 'keyUsage',
		            title: '用法',
		            width: '15',
		            widthUnit: '%',
		            formatter: function(value, row, index) {
		            	return $.table.tooltip(value);
		            }
		        } */,
		        {
		            field: 'publicKeySize',
		            title: '公钥长度'
		        },
		        {
		            field: 'signAlgorithm',
		            title: '签名算法'
		        },
		        {
		            field: 'notAfter',
		            title: '过期时间'
		        },
		        {
		            field: 'status',
		            title: '状态',
		            formatter: function(value, row, index) {
		                if (value == 'NORMAL') {
		                    return '<span class="badge badge-primary">正常</span>';
		                } else if (value == 'REVOKE') {
		                    return '<span class="badge badge-danger">吊销</span>';
		                }else if(value == 'EXPIRE'){
		                	return '过期';
		                }
		            }
		        },
		        {
		            field: 'createDate',
		            title: '创建时间'
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		                var actions = [];
		                actions.push('<a class="btn btn-warning btn-xs " href="javascript:void(0)" onclick="getSignCert(\'' + row.id + '\')"><i class="fa fa-download"></i>下载证书</a>');
		                if(row.parentId!=null && row.status == 'NORMAL'){
		                	 actions.push(' <a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="revokeCa(\'' + row.id + '\')"><i class="fa"></i>吊销</a>');
		                }
		                return actions.join('');
		            }
		        }]
		    };
		    $.treeTable.init(options);
		});
		
		
		
		function getSignCert(id) {
		   window.location.href=prefix+"/getSignCert?id="+id;
		}
		
		function issueRootCa(){
			var id = $.treeTable.selectColumns("id");
			$.modal.openTab("颁发根证书", prefix + "/issueRootCa?id="+id,800);
		}
		
		function revokeCa(id){
			$.modal.open("吊销根证书", prefix + "/revokeCa?id="+id,800,500);
		}
		
		
	</script>
</body>
</html>